import Vue from 'vue'
import Router from 'vue-router'
import routes from '@/router/routers'
import store from '@/store'
import { getCache } from '@/libs/cache'
import { GetCurrentQueryString } from "@/libs/utils";
import { setCache } from '../libs/cache';

Vue.use(Router)

const router = new Router({
    routes
})

router.beforeEach((to, from, next) => {

    const user = store.getters.userinfo
    const cacheUser = getCache({name: 'userinfo'})

    /* if (!user) { //User对象为空
        const openid = GetCurrentQueryString("openid")
        if (openid) {
            //获取用户信息
            store.dispatch("GetUserInfo", openid)
        } else {
            window.location.href = process.env.VUE_APP_BASE_SERVICE_URL + '/wx/mall/user/oauth/oauth_process_userinfo'
        }
    } else {
        if(undefined === cacheUser) {
            setCache({name: 'userinfo', content: user})
        }
    } */

    next()
})

router.afterEach(to => {

})

export default router